package com.gayworld.model.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.gayworld.model.entity.Places;
 

@Repository
public class PlacesDAOImpl extends HibernateBaseDAO<Places> implements PlacesDAO{

	@SuppressWarnings("unchecked")
	@Override
	public List<Places> findInsideOfSquare(Double neLongitud, Double neLatitude,
			Double swLongitud, Double swLatitude, List<Integer> iconSelectedList, int maxResult) { 
		 
		Criteria criteria = getSession().getCurrentSession().createCriteria(Places.class);
	//	DetachedCriteria criteria = DetachedCriteria.forClass(Places.class);

		criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
		criteria.add(Restrictions.between("latitude", neLatitude, swLatitude));
		criteria.add(Restrictions.between("longitude", neLongitud, swLongitud));
		criteria.add(Restrictions.in("icon", iconSelectedList));
		criteria.add(Restrictions.eq("activated", 1));
		/*
		criteria.setProjection(Projections.distinct(
                Projections.groupProperty("id")));
		*/
		criteria.setMaxResults(maxResult);
		 
		return  criteria.list();
	}

}